import { defineStore } from 'pinia'

export const useSystemStore = defineStore({
    id: 'app-system',
    state: (): SystemStore => {
        return {
            locale: null,
            h5ProductUrl: '',
            breadcrumbInfo: [],
        }
    },
    getters: {
        currentLocale: state => state.locale || 'zh-CN',
        currentH5ProductUrl: state => state.h5ProductUrl,
        currentBreadcrumbInfo: (state) => state.breadcrumbInfo,
    },
    actions: {
        updateLocale(locale: 'zh-CN' | 'en-US') {
            this.locale = locale
        },
        updateH5ProductUrl(url = '') {
            this.h5ProductUrl = url
        },
        updateBreadcrumbInfo(breadcrumbInfo = []) {
            this.breadcrumbInfo = breadcrumbInfo;
        },
        addBreadcrumbInfo(breadcrumbItem) {
            this.breadcrumbInfo = [...this.breadcrumbInfo, breadcrumbItem];
        },
    },
    persist: {
        enabled: true,
        strategies: [{ storage: localStorage, paths: ["locale", "h5ProductUrl"] }],
    }
})
